/*    */ package com.zimbra.cs.account.soap;
/*    */ 
/*    */ import com.zimbra.common.account.SignatureUtil;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.util.StringUtil;
/*    */ import com.zimbra.common.zclient.ZClientException;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.Signature;
/*    */ import java.util.HashMap;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ import java.util.Map.Entry;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ class SoapSignature
/*    */   extends Signature
/*    */   implements SoapEntry
/*    */ {
/*    */   SoapSignature(Account acct, String name, String id, Map<String, Object> attrs, Provisioning prov)
/*    */   {
/* 37 */     super(acct, name, id, attrs, prov);
/*    */   }
/*    */   
/*    */   SoapSignature(Account acct, Element e, Provisioning prov) throws ServiceException {
/* 41 */     super(acct, e.getAttribute("name"), e.getAttribute("id"), fromXML(e), prov);
/*    */   }
/*    */   
/*    */   public void modifyAttrs(SoapProvisioning prov, Map<String, ? extends Object> attrs, boolean checkImmutable) throws ServiceException
/*    */   {}
/*    */   
/*    */   public void reload(SoapProvisioning prov) throws ServiceException
/*    */   {}
/*    */   
/*    */   public static void toXML(Element signature, Map<String, Object> attrs) throws ServiceException {
/* 51 */     for (Map.Entry entry : attrs.entrySet()) {
/* 52 */       String attr = (String)entry.getKey();
/* 53 */       String value = (String)entry.getValue();
/*    */       
/* 55 */       if ((attr.equals("zimbraSignatureId")) && (!StringUtil.isNullOrEmpty(value))) {
/* 56 */         signature.addAttribute("id", value);
/* 57 */       } else if ((attr.equals("zimbraSignatureName")) && (!StringUtil.isNullOrEmpty(value))) {
/* 58 */         signature.addAttribute("name", value);
/* 59 */       } else if ((attr.equals("zimbraPrefMailSignatureContactId")) && (!StringUtil.isNullOrEmpty(value))) {
/* 60 */         signature.addElement("cid").setText(value);
/*    */       } else {
/* 62 */         String mimeType = SignatureUtil.attrNameToMimeType(attr);
/* 63 */         if (mimeType == null) {
/* 64 */           throw ZClientException.CLIENT_ERROR("unable to determine mime type from attr " + attr, null);
/*    */         }
/* 66 */         signature.addElement("content").addAttribute("type", mimeType).addText(value);
/*    */       }
/*    */     }
/*    */   }
/*    */   
/*    */   private static Map<String, Object> fromXML(Element signature) throws ServiceException {
/* 72 */     List<Element> contents = signature.listElements("content");
/* 73 */     Map<String, Object> attrs = new HashMap();
/* 74 */     attrs.put("zimbraSignatureId", signature.getAttribute("id"));
/* 75 */     attrs.put("zimbraSignatureName", signature.getAttribute("name"));
/*    */     
/* 77 */     Element eContactId = signature.getOptionalElement("cid");
/* 78 */     if (eContactId != null) {
/* 79 */       attrs.put("zimbraPrefMailSignatureContactId", eContactId.getText());
/*    */     }
/* 81 */     for (Element eContent : contents) {
/* 82 */       String type = eContent.getAttribute("type");
/* 83 */       String attr = SignatureUtil.mimeTypeToAttrName(type);
/* 84 */       if (attr != null) {
/* 85 */         attrs.put(attr, eContent.getText());
/*    */       }
/*    */     }
/*    */     
/* 89 */     return attrs;
/*    */   }
/*    */   
/*    */   public Account getAccount() throws ServiceException {
/* 93 */     throw ServiceException.INVALID_REQUEST("unsupported, use getAccount(Provisioning)", null);
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/soap/SoapSignature.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */